package test.service.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO(这里用一句话描述这个类的作用)
 *
 * @author liuqinghua
 * @date 2023-3-3
 */
public class FieldProcessUtil {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\git\\tag\\table.txt");
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line = null;
        List<String> lines = new ArrayList<String>();
        while ((line = br.readLine()) != null) {
            lines.add(line);
        }
        br.close();
//        getInsertField(lines);
        System.out.println("------------------------------------");
//        getInsertValue(lines);
        System.out.println("------------------------------------");
        getFieldProperty(lines);
        System.out.println("------------------------------------");
//        getInsertValue2(lines);
        System.out.println("------------------------------------");

    }

    public static void getInsertField(List<String> lines) {
        for (String field : lines) {
            String[] ss = field.split("@@@");
            System.out.println("a." + ss[0].trim() + ",");
            System.out.println();
        }
    }

    public static void getFieldProperty(List<String> lines) {
        for (String field : lines) {
            String[] ss = field.split("@@@");
            System.out.println("@ApiModelProperty(\"" + ss[1].trim() + "\")");
            System.out.println("private String " + toCamelCase(ss[0].trim()) + ";");
            System.out.println();
        }
    }

    public static void getInsertValue(List<String> lines) {
        for (String field : lines) {
            String[] ss = field.split("@@@");
            System.out.println("#{" + toCamelCase(ss[0].trim()) + "},");
            System.out.println();
        }
    }

    public static void getInsertValue2(List<String> lines) {
        for (String field : lines) {
            String[] ss = field.split("@@@");
            System.out.println("#{vo." + toCamelCase(ss[0].trim()) + "},");
            System.out.println();
        }
    }

    /**
     * 驼峰式命名法
     */
    public static String toCamelCase(String s) {
        if (s == null) {
            return null;
        }
        s = s.toLowerCase();
        StringBuilder sb = new StringBuilder(s.length());
        boolean upperCase = false;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '_') {
                upperCase = true;
            } else if (upperCase) {
                sb.append(Character.toUpperCase(c));
                upperCase = false;
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

}
